//
//  MYHomeAttentionImageCell.m
//  MuYing
//
//  Created by tbb on 2019/7/23.
//  Copyright © 2019 TBB. All rights reserved.
//

#import "MYHomeAttentionImageCell.h"

@implementation MYHomeAttentionImageCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.bigImageView.hidden = YES;
    self.carousel = [SDCycleScrollView cycleScrollViewWithFrame:CGRectZero delegate:self placeholderImage:[UIImage imageNamed:@"Test_Rectangle_icon"]];
    //设置网络图片数组
    //设置图片视图显示类型
    self.carousel.bannerImageViewContentMode = UIViewContentModeScaleAspectFill;
    self.carousel.clipsToBounds = YES;
    //设置轮播视图的分页控件的显示
    self.carousel.showPageControl = NO;
    [self.contentView addSubview:self.carousel];
    [self.carousel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(UIEdgeInsetsZero);
    }];
    
    _labNum = UILabel.new;
    _labNum.backgroundColor = HexColor(0x999999);
    _labNum.layer.cornerRadius = 8;
    _labNum.layer.masksToBounds = YES;
//    _labNum.layer.borderColor = HexColor(0x414141).CGColor;
//    _labNum.layer.borderWidth = 1;
    _labNum.text = @"1/1";
    _labNum.textColor = HexColor(0xFFFFFF);
    _labNum.font = kFont_Medium(12);
    _labNum.textAlignment = NSTextAlignmentCenter;
    [self.carousel addSubview:_labNum];
    CGFloat width = BoundWithSize(_labNum.text, kScreenWidth, 12).size.width + 10;

    [_labNum mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-12);
        make.top.mas_equalTo(12);
        make.height.mas_equalTo(16);
        make.width.mas_equalTo(width);

    }];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)setModel:(YQPInvitataionModel *)model
{
    _model = model;
    self.carousel.imageURLStringsGroup = _model.imgList;
    if (_model) {
        [self.labNum setText:[NSString stringWithFormat:@"1/%zd",self.carousel.imageURLStringsGroup.count]];
        CGFloat width = BoundWithSize(self.labNum.text, kScreenWidth, 12).size.width + 10;
        [self.labNum mas_updateConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(width);
        }];
    }

}

- (void)setFollowModel:(YQPFollowModel *)followModel
{
    _followModel = followModel;
    self.carousel.imageURLStringsGroup = followModel.invitationImageList;
    
    if (_followModel) {
        [self.labNum setText:[NSString stringWithFormat:@"1/%zd",self.carousel.imageURLStringsGroup.count]];
        CGFloat width = BoundWithSize(self.labNum.text, kScreenWidth, 12).size.width + 10;
        [self.labNum mas_updateConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(width);
        }];
    }

}

- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didScrollToIndex:(NSInteger)index
{
    if (_model) {
        [self.labNum setText:[NSString stringWithFormat:@"%ld/%lu",index + 1,(unsigned long)self.model.imgList.count]];

    }else{
        [self.labNum setText:[NSString stringWithFormat:@"%ld/%lu",index + 1,(unsigned long)self.followModel.invitationImageList.count]];
    }
    CGFloat width = BoundWithSize(self.labNum.text, kScreenWidth, 12).size.width + 10;
    [self.labNum mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(width);
    }];
}

/** 点击图片回调 */
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index {

    YQBaseImageBrowserVC *imageBrowser = [[YQBaseImageBrowserVC alloc] initImageArrUrl:self.carousel.imageURLStringsGroup currentIndex:index sourceObject:cycleScrollView];
    imageBrowser.currentPage = index;
    [imageBrowser show];

}

@end
